from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import pywinauto
from webdriver_manager.chrome import ChromeDriverManager

# 初始化浏览器对象
driver = webdriver.Chrome(ChromeDriverManager().install())
# 最大化浏览器
driver.maximize_window()
# 打开网易见外工作台首页
driver.get("https://jianwai.youdao.com/")
time.sleep(3)

# 定位iframe表单
frame_element = driver.find_element(By.CSS_SELECTOR, "iframe[id]")
# 切换进入表单
driver.switch_to.frame(frame_element)
# driver.switch_to_frame(frame_element)

# 输入账号
driver.find_element(By.CSS_SELECTOR, "input[name=email]").send_keys("974381044@qq.com")
time.sleep(1)
# 输入密码
driver.find_element(By.XPATH, "//input[@name='password']").send_keys("zytc@12310120")
time.sleep(1)
# 点击-登录
driver.find_element(By.ID, "dologin").click()
time.sleep(5)

# 点击-新建项目
driver.find_element(By.XPATH, "//div[@class='btn btn-add']").click()
time.sleep(1)
# 点击-图片翻译
driver.find_element(By.XPATH, "//div[text()='图片翻译']").click()
time.sleep(2)
# # input标签,可以直接使用send_keys()上传文件
# driver.find_element(By.XPATH, "//input[@class='file']").send_keys(r"C:\TT\习知\12\my_test_demo_12\seleniumDemo\1624958787(1).png")

# 非input标签
driver.find_element(By.XPATH, "//input[@class='file']/..").click()
time.sleep(1)
app = pywinauto.Desktop()
win = app['打开']
win['Edit'].type_keys(r"C:\TT\习知\12\my_test_demo_12\seleniumDemo\1624958787.png")
time.sleep(1)
win['Button'].click()

time.sleep(5)
driver.quit()